const Model = require('../models/menuModel')

const create = async (ctx) => {
  const { menu_name, menu_title, route_path, vue_file_path, parent_menu_id } = ctx.request.body
  console.log(menu_name, menu_title, route_path, vue_file_path, parent_menu_id)
  await Model.create(menu_name, menu_title, route_path, vue_file_path, parent_menu_id)
  ctx.body = { success: true }
}

const update = async (ctx) => {
  const { menu_name, menu_title, route_path, vue_file_path, parent_menu_id, menu_id } = ctx.request.body
  await Model.update(menu_name, menu_title, route_path, vue_file_path, parent_menu_id, menu_id)
  ctx.body = { success: true }
}
const removeById = async (ctx) => {
  const { menuId } = ctx.request.body
  await Model.removeById(menuId)
  ctx.body = { success: true }
}
const findById = async (ctx) => {
  const { id } = ctx.params
  ctx.body = { success: true, data: await Model.findById(id) }
}
const findAll = async (ctx) => {
  ctx.body = { success: true, data: await Model.findAll() }
}
const findByRoleId = async (ctx) => {
  const { role_id } = ctx.query
  ctx.body = { success: true, data: await Model.findByRoleId(role_id) }
}
const getMenuTree = async (ctx) => {
  ctx.body = { success: true, data: await Model.getMenuTree() }
}

module.exports = {
  create,
  update,
  removeById,
  findById,
  findAll,
  findByRoleId,
  getMenuTree,
}
